<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="text" id="i2">
<input type="button" value="加" onclick="f('加')">
<input type="button" value="减" onclick="f('减')">
<input type="button" value="乘" onclick="f('乘')">
<input type="button" value="除" onclick="f('除')">

<div>
    结果：<span></span>
</div>


<script>


    let d1 = document.querySelector("#i1");
    let d2 = document.querySelector("#i2");
    let result = document.querySelector("span");
    function f(name){
        if(isNaN(d1.value) || isNaN(d2.value)){
            result.innerText = "输入错误";
            return;
        }
        switch (name){
            case '加':
                result.innerText = parseFloat(d1.value) + parseFloat(d2.value);
                break;
            case '减':
                result.innerText = parseFloat(d1.value) - parseFloat(d2.value);
                break;
            case '乘':
                result.innerText = parseFloat(d1.value) * parseFloat(d2.value);
                break;
            case '除':
                result.innerText = parseFloat(d1.value) / parseFloat(d2.value);
                break;
        }


    }




</script>


</body>
</html>